package com.yanqu.road.server.cmd.activity.seacraftsouthsea;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.pb.activity.SeacraftSouthSeaProto;
import com.yanqu.road.server.cmd.CrossUnionCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.activity.ActivityMgr;
import com.yanqu.road.server.manager.activity.peakseacraft.PeakSeacraftMgr;
import com.yanqu.road.server.manager.activity.seacraftsouthsea.SeacraftSouthSeaMgr;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

/**
 * @Description
 * @Author cwq
 * @Data 2022/1/20 17:21
 */
@Cmd(code = CrossProtocol.C2_SEACRAFT_SOUTH_SEA_RECEIVE_UNION_RANK, desc = "海上争霸 南海丝路 领取联盟排行奖励")
public class CrossSeacraftSouthSeaReceiveUnionRankCmd extends CrossUnionCommand {

    long userId;
    int activityId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        SeacraftSouthSeaProto.SeacraftSouthSeaReceiveUnionRankReqMsg reqMsg = SeacraftSouthSeaProto.SeacraftSouthSeaReceiveUnionRankReqMsg.parseFrom(packet.getBytes());
        userId = packet.getPlayerId();
        activityId = reqMsg.getActivityId();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        ActivityInfo activityInfo = ActivityMgr.getActivityInfoMayLoadDB(activityId);
        if (null == activityInfo) {
            return;
        }
        SeacraftSouthSeaProto.SeacraftSouthSeaReceiveUnionRankCrossToGameMsg.Builder respMsg = SeacraftSouthSeaProto.SeacraftSouthSeaReceiveUnionRankCrossToGameMsg.newBuilder();
        if (activityInfo.getType() == eActivityType.SeacraftActivity.getValue()) {
            respMsg = SeacraftSouthSeaMgr.receiveUnionRank(activityId, userId);
        } else if (activityInfo.getType() == eActivityType.PeakSeacraftActivity.getValue()) {
            respMsg = PeakSeacraftMgr.receiveUnionRank(activityId, userId);
        } else {
            return;
        }
        YanQuMessage pbMsg = YanQuMessageUtils.buildMessage(GameProtocol.S_SEACRAFT_SOUTH_SEA_RECEIVE_UNION_RANK_FROM_CROSS, respMsg);
        MessageHelper.sendPacket(serverId, userId, pbMsg);
    }

    @Override
    public void sendData() {

    }
}
